C ++位集函数用于访问值到位集的任何索引。
boolean operator [] (int pos); reference operator[] (int pos);
pos strong>:参数 index strong>指定要分配值的位置 strong>。
该函数将值返回到索引处的位。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-bitset-operator[]-function.html
来源:LearnFk无涯教程网
#include <iostream> #include <bitset> using namespace std; int main() { bitset<4> b; b[1]=1; b[2]=b[1]; cout<< "b :" << b; return 0; }
输出 strong>:
b :0110
#include <iostream> #include <bitset> using namespace std; int main() { bitset<4> b(string("1001")); b[1]=1; b[2]=b[1]; cout<< "b :" << b; return 0; }
输出 strong>:
b :1111
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)